package com.qf.service.impl;

import com.qf.entity.Merchant_category;
import com.qf.mapper.Merchant_categoryMapper;
import com.qf.service.Merchant_categoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

//商家分类业务逻辑层
@Service
public class Merchant_categoryServiceImpl implements Merchant_categoryService {

    @Autowired
    private Merchant_categoryMapper merchant_categoryMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 查询所有的商家分类
     * @return
     */
    @Override
    public List<Merchant_category> selAllMerchant_category() {
        Boolean bool = redisTemplate.hasKey("mc");
        List list = null;
        if (!bool) {  //没有
            List<Merchant_category> mcList = merchant_categoryMapper.selAllMerchant_category();//数据库查询
            System.out.println("AAAAAAAAAAAAAAAAAAA---数据库查询---AAAAAAAAAAAAAAAAAAAAAA");
            redisTemplate.opsForList().rightPushAll("mc", mcList); //往redis放一份
            list = redisTemplate.opsForList().range("mc", 0, -1);//直接redis取值
            System.out.println("22222222222288888888888888888888888888-----------------------------------");
            return list;
        } else { //有
            System.out.println("AAAAAAAAAAAAAAAAAAA---redis查询---AAAAAAAAAAAAAAAAAAAAAA");
            list = redisTemplate.opsForList().range("mc", 0, -1);//直接redis取值
        }
        return list;
    }
}
